package com.mini.repository;

import com.mini.model.BusinessBelongingInfo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.List;

/**
 * @author: zhaocg
 * @created: 2020/12/02 11:56
 */
@Repository
public interface BusinessBelongingInfoRepository extends JpaRepository<BusinessBelongingInfo, Long>, JpaSpecificationExecutor<BusinessBelongingInfo>{

    List<BusinessBelongingInfo> findTop2ByBusinessGroupIdOrderByCreateTimeDesc(Long groupId);

    Long countByBusinessGroupId(Long groupId);

    List<BusinessBelongingInfo> findByBusinessGroupIdOrderByCreateTimeDesc(Long groupId);

    @Modifying
    @Query("delete from BusinessBelongingInfo belonging where belonging.businessGroupId = :groupId")
    void deletedByGroupId(@Param("groupId") Long groupId);

    List<BusinessBelongingInfo> findByBusinessGroupIdIn(List<Long> businessGroupIds);

    List<BusinessBelongingInfo> findByLegionId(Long legionId);
}
